#include <common.h>

unsigned int timer_ticks = 0;

void timer_phase(int hz)
{
    int divisor = 1193180 / hz;       /* Calculate our divisor */
    outportb(0x43, 0x36);             /* Set our command byte 0x36 */
    outportb(0x40, divisor & 0xFF);   /* Set low byte of divisor */
    outportb(0x40, divisor >> 8);     /* Set high byte of divisor */
}

void time_handler()//struct regs *r)
{
	timer_ticks++;
	if (timer_ticks % 25 == 0)
	{
		//print("Tt");
	}
}

void init_timer()
{
	timer_phase(100);
	irq_install_handler(0, time_handler);
}

void timer_sleep(int ticks)
{
	unsigned long eticks;
	
	eticks = timer_ticks + ticks;
	while (timer_ticks < eticks);
}